<?php
namespace app\index\controller;


use app\Logic\OpensslLogic;

class Single
{
    public function index()
    {
        $token = input('token');
        isset($token) or die('token为空');

        $url = 'http://apidev.tiantiankaidan.com/singleLogin/checkToken';
        $param = ['token'=>$token];
        $res = $this->testCurlPost($url,$param,false);
        $res = json_decode($res,true);
        echo "</br>";
        if (isset($res['returnCode']) && $res['returnCode'] == 1001){
            echo 'token验证成功';
            echo "</br>";
            echo "解析uuid,加密数据：{$res['data']['uuid']}";
            echo "</br>";
            $uuid = OpensslLogic::decode($res['data']['uuid']);
            echo '解密成功uuid:';
        }else{
            echo 'token验证失败';
        }
    }

    public function testCurlPost($url = '', $param = '',$dataDeal = true) {
        if (empty($url) || empty($param)) {
            return false;
        }

        $postUrl = $url;
        $curlPost = $dataDeal ? http_build_query($param) : $param;

        dump('发送信息：',$curlPost);

        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);//运行curl


        if (curl_errno($ch)) {
            echo 'Curl error: ' . curl_error($ch);
        }
        dump('天天开单返回信息:',$data);
        curl_close($ch);

        /*$tmp = array();
        $tmp['url'] = $url;
        $tmp['发送信息'] = $curlPost;
        $tmp['bfq返回信息'] = $data;
        $data = json_encode($tmp);*/

        return $data;
    }
}
